<?php
/**
 * @copyright:Copyright (C) 2010-2014 LiZaoNet Inc. (http://www.lizaonet.com)
 * @license: http://www.lizaonet.com
 * @link:http://www.lizaonet.com
 * @since:File available since Release v1.0
 * @Created by Azrael
 * @User: Azrael
 * @Date: 2016/1/27
 * @Time: 15:33
 *
 */

namespace Home\Logic;


use Home\Model\UserlistModel;

class UserLogic
{

    private $model = null;

    public function __construct()
    {
        $this->model = new UserlistModel();
    }

    public function getAdminUser($mid)
    {
        return $this->model->getUserInfoGroupByMid($mid);
    }

    /**
     * 获取用户信息
     * @param $mid
     * @param $fid
     * @return array|mixed
     */
    public function getUserInfo($mid, $fid)
    {
        $userinfo = $this->model->getUserByMidFid($mid, $fid);
        if (!$userinfo) {
            $username = generateGuidUser();
            $userinfo = array(
                'username' => "游客" . $username,
                'adminid' => 14,
                'dateline' => time(),
                'fid' => $fid,
                'type' => 1
            );
            $id = $this->model->addUser($userinfo);
            $userinfo["mid"] = $id;
            $userinfo['leixing'] = "游客";
        } else {
            $userinfo = $this->model->getUserInfoGroupByMid($mid);
            $userinfo['type'] = 2;
        }
        return $userinfo;
    }

    /**
     * 统计推荐的人数
     * @param $tuijianMid
     * @return int
     */
    public function getTotalTuijian($tuijianMid)
    {
        return $this->model->getTotal($tuijianMid);
    }

}